package com.springboot.springbootredis.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * @Author: TongRui乀
 * @Date: 2020-08-19 19:37
 * @description：  消息消费者
 */
@Slf4j
@Component
public class RedisMessageListener implements MessageListener {
    @Override
    public void onMessage(Message message, byte[] pattern) {

        log.info("pattern-{}", new String(pattern));

        RedisSerializer serializer=new GenericJackson2JsonRedisSerializer();

        log.info("message-{}", serializer.deserialize(message.getBody()));
    }
}
